//
//  QKT.h
//  Chart
//
//  Created by CaoJun on 15/9/14.
//
//

#ifndef __Chart__QKT__
#define __Chart__QKT__

#include "KLineData.h"
#include "IndexData.h"

#include <string>
#include <vector>

namespace ytx
{
    namespace QKTType {
        enum QKTType{
            Short = -1,
            Flat = 0,
            Long = 1
        };
    }
    
    struct QKTItem {
        YTXTime tradedatepre;
        QKTType::QKTType type;
        YTXTime tradedatenext;
    };
    
    class QKT : public IndexData
    {
    public:
        QKT(IndexConfig indexConfig);
        
        virtual void calculate(Quotation * data);
        
        virtual void updateLastest(Quotation * data);
        
        virtual void callback(std::string tag, std::string data);
        
        virtual void onFail(std::string tag);
        
        virtual void clearIfParentDataChanged(const Quotation * data);
        
        virtual void cleanData();
    private:
        bool requesLock;
        
    protected:
        KLineData * kLineData;
        std::vector<QKTItem> QKTData;
        virtual std::vector<QKTItem> getQKTDataFromDB();
        virtual bool updateQKTData(QKTItem);
        virtual void getQKTData();
        virtual void requestQKTData(std::string date);
        virtual void responseQKTData(YTXJson::Value data, YTXJson::Value info);
        virtual bool QKTDataIsEnough();
        virtual bool saveQKTDataToDB(std::vector<QKTItem>);
        virtual bool hasQKTData();
        virtual void setQKTData(QKTItem qk);
        
        virtual void realCalculate(KLineData * data);
    };
}

#endif /* defined(__Chart__QKT__) */
